﻿using Microsoft.Xna.Framework;
using WindowsGame.GameObject;
using WindowsGame.Manager;
using NUnit.Framework;
using Rhino.Mocks;

namespace Tutorial10.Tests.Manager
{
	[TestFixture]
	public class GameObjectManagerTests
	{
		// System under test.
		private IGameObjectManager gameObjectManager;

		private ICameraManager cameraManager;
		private IContentManager contentManager;
		private IInputManager inputManager;
		private SpaceShip spaceShip;
		private readonly GameTime gameTime = new GameTime();

		[SetUp]
		public void SetUp()
		{
			cameraManager = MockRepository.GenerateStub<ICameraManager>();
			contentManager = MockRepository.GenerateStub<IContentManager>();
			inputManager = MockRepository.GenerateStub<IInputManager>();
			spaceShip = new SpaceShip();

			gameObjectManager = new GameObjectManager(cameraManager, contentManager, inputManager, spaceShip);
		}

		[Test]
		public void Warp()
		{
			// Arrange.
			Vector3 modelPostion = new Vector3(10, 20, 30);
			spaceShip = new SpaceShip(modelPostion);

			gameObjectManager = new GameObjectManager(cameraManager, contentManager, inputManager, spaceShip);
			inputManager.Stub(im => im.Warp()).Return(true);

			// Act.
			gameObjectManager.Update(gameTime);

			// Assert.
			Assert.AreEqual(Vector3.Zero, gameObjectManager.SpaceShip.ModelPosition);
		}

		[Test]
		public void Left()
		{
			// Arrange.
			inputManager.Stub(im => im.Rotate()).Return(-1);

			// Act.
			gameObjectManager.Update(gameTime);

			// Assert.
			Assert.AreEqual(0.1f, gameObjectManager.SpaceShip.ModelRotation);
		}

		[Test]
		public void Right()
		{
			// Arrange.
			inputManager.Stub(im => im.Rotate()).Return(1);

			// Act.
			gameObjectManager.Update(gameTime);

			// Assert.
			Assert.AreEqual(-0.1f, gameObjectManager.SpaceShip.ModelRotation);
		}

		[Test]
		public void Move()
		{
			// Arrange.
			inputManager.Stub(im => im.Move()).Return(1);

			// Act.
			gameObjectManager.Update(gameTime);

			// Assert.
			Assert.AreEqual(-1.0f, gameObjectManager.SpaceShip.ModelPosition.Z);
		}

		[TearDown]
		public void TearDown()
		{
			gameObjectManager = null;

			cameraManager = null;
			contentManager = null;
			inputManager = null;
			spaceShip = null;
		}
	}
}
